package com.blrs.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.blrs.common.annotation.RepeatSubmit;
import com.blrs.common.utils.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.blrs.common.annotation.Log;
import com.blrs.common.core.controller.BaseController;
import com.blrs.common.core.domain.AjaxResult;
import com.blrs.common.enums.BusinessType;
import com.blrs.domain.BusinessFollowRecords;
import com.blrs.service.enterprise.records.IBusinessFollowRecordsService;
import com.blrs.common.utils.poi.ExcelUtil;
import com.blrs.common.core.page.TableDataInfo;

/**
 * 商机跟进记录Controller
 * 
 * @author ruoyi
 * @date 2023-09-25
 */
@RestController
@RequestMapping("/businessFollow/records")
public class BusinessFollowRecordsController extends BaseController
{
    @Autowired
    private IBusinessFollowRecordsService businessFollowRecordsService;

    /**
     * 查询商机跟进记录列表
     */
    //@PreAuthorize("@ss.hasPermi('system:records:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusinessFollowRecords businessFollowRecords)
    {
        startPage();
        List<BusinessFollowRecords> list = businessFollowRecordsService.selectBusinessFollowRecordsList(businessFollowRecords);
        return getDataTable(list);
    }

    /**
     * 导出商机跟进记录列表
     */
    //@PreAuthorize("@ss.hasPermi('system:records:export')")
    @Log(title = "商机跟进记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusinessFollowRecords businessFollowRecords)
    {
        List<BusinessFollowRecords> list = businessFollowRecordsService.selectBusinessFollowRecordsList(businessFollowRecords);
        ExcelUtil<BusinessFollowRecords> util = new ExcelUtil<BusinessFollowRecords>(BusinessFollowRecords.class);
        util.exportExcel(response, list, "商机跟进记录数据");
    }

    /**
     * 获取商机跟进记录详细信息
     */
   // @PreAuthorize("@ss.hasPermi('system:records:query')")
    @GetMapping(value = "/{recordsId}")
    public AjaxResult getInfo(@PathVariable("recordsId") String recordsId)
    {
        return success(businessFollowRecordsService.selectBusinessFollowRecordsByRecordsId(recordsId));
    }

    /**
     * 新增商机跟进记录
     */
    //@PreAuthorize("@ss.hasPermi('system:records:add')")
    @Log(title = "商机跟进记录", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit(interval = 1000,message = "请勿重复提交！")
    public AjaxResult add(@RequestBody BusinessFollowRecords businessFollowRecords)
    {
        return toAjax(businessFollowRecordsService.insertBusinessFollowRecords(businessFollowRecords));
    }

    /**
     * 修改商机跟进记录
     */
    //@PreAuthorize("@ss.hasPermi('system:records:edit')")
    @Log(title = "商机跟进记录", businessType = BusinessType.UPDATE)
    @PutMapping
    @RepeatSubmit(interval = 1000,message = "请勿重复提交！")
    public AjaxResult edit(@RequestBody BusinessFollowRecords businessFollowRecords)
    {
        return toAjax(businessFollowRecordsService.updateBusinessFollowRecords(businessFollowRecords));
    }
    /**
     * 批注商机跟进记录
     */
    @PutMapping("/remark")
    @RepeatSubmit(interval = 1000,message = "请勿重复提交！")
    public AjaxResult remark(@RequestBody BusinessFollowRecords businessFollowRecords)
    {
            return toAjax(businessFollowRecordsService.updateBusinessFollowRecordsRemark(businessFollowRecords));
        }

    /**
     * 删除商机跟进记录
     */
    //@PreAuthorize("@ss.hasPermi('system:records:remove')")
    @Log(title = "商机跟进记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordsIds}")
    public AjaxResult remove(@PathVariable String[] recordsIds)
    {
        return toAjax(businessFollowRecordsService.deleteBusinessFollowRecordsByRecordsIds(recordsIds));
    }

    @GetMapping("/getRemarkByRecordsId/{businessId}")
    public AjaxResult isExamine(@PathVariable("businessId") String businessId){
        return toAjax(businessFollowRecordsService.getRemarkByRecordsId(businessId));
    }

}
